package com.sun.dream.fish.mvc;

import com.sun.dream.fish.mvc.exception.DSFException;
import com.sun.dream.fish.mvc.exception.ValidResult;
import com.sun.dream.fish.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Description:  全局异常处理
 * Created By ljl on 2023/11/24.
 */
@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ResultVO<String> handleOtherExceptions(Exception ex) {
        log.error("[全局异常], ", ex);
        // 处理其他类型的异常的逻辑
        return new ResultVO<>(null, 500, ex.getMessage());
    }

    @ExceptionHandler(DSFException.class)
    public ResultVO<ValidResult> handleCustomException(DSFException ex) {
        log.error("[全局异常], ", ex);
        // 处理自定义异常的逻辑
        return new ResultVO<>(ex.getValidResult(), 500, ex.getMessage());
    }


    @ExceptionHandler(Throwable.class)
    public ResultVO<String> handleThrowable(Throwable ex) {
        log.error("[全局异常], ", ex);
        // 处理其他类型的异常的逻辑
        return new ResultVO<>(null, 500, ex.getMessage());
    }
}
